{extend name="../../../view/public/base" /}

{block name="css"}
<style>
    body {
        background-color: #F2F2F2;
    }

    .xm-body {
        height: 400px !important;
        overflow-y: scroll !important;
    }

    .layui-form-selected dl {
        height: 200px !important;
        overflow-y: scroll !important;
    }
</style>
{/block}

{block name="body"}
<div style="padding: 20px; background-color: #F2F2F2;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card" style="padding: 20px">
                <br><br>
                <form class="layui-form" lay-filter="addForm" autocomplete="off">
                    <input type="hidden" id="id" name="id" value="{$data.id? $data.id : 0}"/>
                    <input type="hidden"  name="rule_ids" value="{$data.rule_ids? $data.rule_ids : ''}"/>
                    <!--分类id-->

                    <!--单图-->
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red">*</span>头部LOGO</label>
                        <div class="layui-input-block">
                            <input type="hidden" name="avatar" class="layui-input">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn layui-btn-normal" id="avatar">上传头部LOGO</button>
                                <div class="layui-upload-list" id="avatarPreview" style="display: flex;">
                                    <!--加载默认图片-->
                                    <script>
                                        getImagesHtmlForEdit('{$data.avatar? $data.avatar : ""}', 'avatar')
                                    </script>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red">*</span>昵称</label>
                        <div class="layui-input-block">
                            <input type="text" name="nickname" lay-verify="required" placeholder="昵称" autocomplete="off" class="layui-input" value="{$data.nickname?$data.nickname:''}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red">*</span>电子邮箱</label>
                        <div class="layui-input-block">
                            <input type="email" name="email" placeholder="电子邮箱" autocomplete="off" class="layui-input"  value="{$data.email?$data.email:''}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" lay-verify="required" placeholder="用户名"  onkeyup="this.value=this.value.replace(/[^\w_]/g,'');" autocomplete="off" class="layui-input" value="{$data.username?$data.username:''}" disabled>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="submitBtn">更新</button>
                        </div>
                    </div>
                </form>
                <br><br>
            </div>
        </div>
    </div>
</div>

{/block}

{block name="js"}
<script>
    var layer, form, bwajax, upload, $, laydate,manage,xmSelect,eleTree;

    layui.use(['layer', 'form', 'bwajax', 'upload', 'laydate', 'manage', 'xmSelect','eleTree'], function () {
        layer = layui.layer;
        form = layui.form;
        bwajax = layui.bwajax.instance();
        upload = layui.upload;
        $ = layui.jquery;
        laydate = layui.laydate;
        manage = layui.manage;
        xmSelect = layui.xmSelect;
        eleTree = layui.eleTree;

        //添加时间 日期时间选择器
        laydate.render({
            elem: '#add_time'
            ,type: 'datetime'
        });


        var uploadInst = bw_upload(upload, 'avatar', 'image');


        //监听提交按钮
        form.on('submit(submitBtn)', function (obj) {
            data = obj.field;
            var is_super = '{$is_super}';
            // console.log(is_super);
            // if(is_super!=1){
            //     if(!data.rule_ids) {layer.msg('请选择角色', {icon: 2});return false}
            // }

            if(!data.username) {layer.msg('用户名不能为空', {icon: 2});return false}
            if(!data.nickname) {layer.msg('昵称不能为空', {icon: 2});return false}

            delete data['eleTree-node'];
            delete data.select;
            var post_url = "/manage/admin/userSetting";

            //console.log(data);return false;
            //ajax调用后台接口
            bwajax.post(post_url, data)
                .then(function (response) {
                    if (response.data.data.errcode === 0) {
                        layer.msg('提交成功', {icon: 1});
                        submitSuccess();

                    } else {
                        layer.msg(response.data.msg, {icon: 2});

                    }
                })

            return false;
        })
    });


    function submitSuccess() {
        parent.location.reload();//这里调用的是父页面的reload方法
        setTimeout(function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }, 1000);
    }

    // //粉丝
    // function getNum(){
    //
    //     layer.open({
    //         type: 2,
    //         title: '图标列表',
    //         shade: 0.8,
    //         //closeBtn: 0, //不显示关闭按钮
    //         shade: [0],
    //         shadeClose: true,//单机空白处消失
    //         maxmin: true,
    //         //anim: 4, //动画类型
    //         area: ['40%','90%'],
    //         content:"{:Url('public_common/icon')}",
    //         btn: ['选择图标'],
    //         yes: function(index, layero){
    //
    //             var nodeName = window["layui-layer-iframe" + index];//父页面引用
    //             var icon = nodeName.getIcon();
    //             if(icon!=false){
    //                 $('#icon').val(icon);
    //                 layer.close(index);
    //                 //处理重复提交
    //             }
    //
    //
    //
    //
    //
    //         }
    //     });
    // }
</script>
{/block}